package cn.edu.leetcode.数组操作;

public class 移除元素 {

    public static void main(String[] args) {
        int[] nums = {0, 1, 2, 2, 3, 0, 4, 2};
        int val = 2;

        System.out.println(removeElement(nums, val));
        for (int x : nums) {
            System.out.print(x);
        }
    }

    public static int removeElement(int[] nums, int val) {
        int p = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val){
                nums[p] = nums[i];
                p++;
            }
        }
        return p;
    }
}
